﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyLirarySystem
{
    public partial class test : Form
    {
        public test()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 获取输入值
            string manageID = ManageID.Text.Trim();
            string password = Pwd.Text.Trim();

            // 验证输入
            if (string.IsNullOrEmpty(manageID) || string.IsNullOrEmpty(password))
            {
                MessageBox.Show("管理ID和密码不能为空！", "输入错误",
                              MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // 构建SQL语句（注意：这里应该使用参数化查询，但为了测试先直接拼接）
            string sql = $"INSERT INTO Admin(ManageID, Pwd) VALUES('{manageID}', '{password}')";

            // 执行插入
            int result = DBHelper.ExecuteNonQuery(sql);

            // 处理结果
            if (result > 0)
            {
                MessageBox.Show($"成功添加管理员：{manageID}", "操作成功",
                              MessageBoxButtons.OK, MessageBoxIcon.Information);
                ManageID.Clear();
                Pwd.Clear();
                ManageID.Focus();
            }
            else if (result == -1)
            {
                MessageBox.Show("添加失败：数据库错误", "操作失败",
                              MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("添加失败：未知原因", "操作失败",
                              MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
    
}
